public class BinaryTree {
    static class TreeNode{
        public  char val;
        public TreeNode left;
        public TreeNode right;
        public TreeNode(char val){
            this.val=val;
        }
    }
    public TreeNode createTree(){
        TreeNode A = new TreeNode('A');
        TreeNode B = new TreeNode('B');
        TreeNode C = new TreeNode('C');
        TreeNode D = new TreeNode('D');
        TreeNode E = new TreeNode('E');
        TreeNode F = new TreeNode('F');
        TreeNode G = new TreeNode('G');
        TreeNode H = new TreeNode('H');
        A.left = B;
        A.right = C;
        B.left = D;
        B.right = E;
        E.right = H;
        C.left = F;
        C.right = G;
        return A;
    }
    //前序遍历(根→左→右）
    public void preOrder(TreeNode root) {
        if(root==null){
            return;
        }
        System.out.println(root.val+" ");
        preOrder(root.left);
        preOrder(root.right);
    }
    //中序遍历(左→根→右)
    public void inOrder(TreeNode root) {
        if(root==null){
            return;
        }
        preOrder(root.left);
        System.out.println(root.val+" ");
        preOrder(root.right);
    }
    //后序遍历(左→右→根)
    public void postOrder(TreeNode root) {
        if(root==null){
            return;
        }
        preOrder(root.left);
        preOrder(root.right);
        System.out.println(root.val+" ");
    }
    public static int countSize = 0;
    // 获取树中节点的个数   遍历思路  O(N)
    public void size(TreeNode root) {
        if(root == null) {
            return ;
        }
        countSize++;
        size(root.left);
        size(root.right);
    }
    public int nodeSize(TreeNode root) {
        if(root == null) {
            return 0;
        }
        return nodeSize(root.left)
                + nodeSize(root.right) + 1;
    }

}
